<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core">

<table>
	<tr>
		<td>
			<h:panelGrid columns="2">
				<h:outputText value="Nome do Animal" styleClass="required"/>
				<p:inputText value="#{animalManager.animal.nome}" disabled="#{animalManager.disableInputs}" required="true" label="Nome do Animal"/>
				
				<h:outputText value="Data de Nascimento" />
				<p:calendar value="#{animalManager.animal.dataNascimento}" datePattern="dd/MM/yyyy" yearRange="1900" locale="pt"
						label="Data de Nascimento" id="data_nascimento_animal" navigator="true" readOnlyInputText="true" disabled="#{animalManager.disableInputs}"/>
				
				<h:outputText value="Espécie" styleClass="required"/>
				<p:selectOneMenu id="especie" value="#{animalManager.animal.especie.id}" required="true" style="width:150px;" disabled="#{animalManager.disableInputs}" label="Espécie">
					<f:selectItem itemLabel="- Selecione -"/>
					<f:selectItems value="#{animalManager.especies}" var="especie" itemLabel="#{especie.descricao}" itemValue="#{especie.id}" />
				</p:selectOneMenu>
				
				<h:outputText value="Raça" styleClass="required"/>
				<p:selectOneMenu id="raca" value="#{animalManager.animal.raca.id}" required="true" style="width:150px;" disabled="#{animalManager.disableInputs}" label="Raça">
					<f:selectItem itemLabel="- Selecione -"/>
					<f:selectItems value="#{animalManager.racas}" var="raca" itemLabel="#{raca.descricao}" itemValue="#{raca.id}" />
				</p:selectOneMenu>
				
				<h:outputText value="Pelagem" styleClass="required"/>
				<p:selectOneMenu id="pelagem" value="#{animalManager.animal.pelagem.id}" required="true" style="width:150px;" disabled="#{animalManager.disableInputs}" label="Pelagem">
					<f:selectItem itemLabel="- Selecione -"/>
					<f:selectItems value="#{animalManager.pelagens}" var="pelagem" itemLabel="#{pelagem.descricao}" itemValue="#{pelagem.id}" />
				</p:selectOneMenu>
				
				<h:outputText value="Vivo?" styleClass="required"/>
				<p:selectBooleanCheckbox value="#{animalManager.animal.vivo}" disabled="#{animalManager.disableInputs}" required="true" label="Vivo?"/>
				
				<h:outputText value="Peso" styleClass="required"/>
				<p:inputText value="#{animalManager.animal.peso}" disabled="#{animalManager.disableInputs}" required="true" label="Peso"/>
				
				<h:outputText value="Pedigree" />
				<p:inputText value="#{animalManager.animal.numeroPedigree}" />
				
				<h:outputText value="ID Digital" />
				<p:inputText value="#{animalManager.animal.idDigital}" />
			</h:panelGrid>
		</td>
		<td>
			<table>
				<tr>
					<td style="vertical-align: top">
						<h:outputText value="Imagem" />
						<p:photoCam widgetVar="pc" listener="#{imagemManager.oncapture}" update="content" process="@this" />
					</td>
					<td style="vertical-align: top">
						<h:outputText value="Imagem Carregada" />
						<br />
						<p:graphicImage value="#{imagemManager.foto}" id="content"/>
					</td>
				</tr>
			</table>
			<p:commandButton type="button" value="Capturar"  onclick="pc.capture()" />
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<p:commandButton action="#{animalManager.addAnimal}" value="Incluir" update="panel_table_animal :form:growl" rendered="#{clienteManager.isCpfValido and animalManager.animal.id == null}"/>
			<p:commandButton action="#{animalManager.update}" value="Atualizar" update=":form_animal :form:growl" rendered="#{clienteManager.isCpfValido and animalManager.animal.id != null}"/>
				
			<h:panelGroup id="panel_table_animal" rendered="#{clienteManager.isCpfValido}">
				<p:dataTable value="#{animalManager.animais}" var="animal" rows="3" paginator="true" paginatorPosition="top">
					<p:column headerText="Nome">
						<h:outputText value="#{animal.nome}" />
					</p:column>
					<p:column headerText="Nascimento">
						<h:outputText value="#{animal.dataNascimento}" >
							<f:convertDateTime pattern="dd/MM/yyyy" />
						</h:outputText> 
					</p:column>
					<p:column headerText="Ação">
						<p:commandButton action="#{animalManager.prepareUpdate}" value="Atualizar" update=":form_animal" process="@this">
							<f:setPropertyActionListener target="#{animalManager.animal}" value="#{animal}"></f:setPropertyActionListener>
						</p:commandButton>
					</p:column>
				
				</p:dataTable>
			</h:panelGroup>
		</td>
	</tr>
</table>
</html>